<template>
<div class="">
    <p>
        <span class="tit1">武汉各等级老年人口数</span>
    </p>
    <div ref="chart1" class='top20' style="width: 100%; height: 300px" />
</div>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
export default {
    components: {},
    props: {},
    data() {
        return {                                                
            chartData: {
                color: [ '#4E7FE6','#FFAE38','#FF5D52' ],
                data1: ['2014年', '2015年', '2016年','2017年','2018年', '2019年', '2020年'],
                data2: [311,898,432,432,311,898,432],
                data3: ['人口数']
            }
        }
    },
    computed: {},
    watch: {

    },
    created() {
        const t = this;

    },
    mounted() {
        const t = this;
        t.initChart();
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$refs.chart1, 'macarons')
            this.setOptions()
        },
        setOptions() {
            const t = this;
            this.chart.setOption({
                color: t.chartData.color,
                tooltip: {
                    trigger: 'axis'
                },
                grid: {
                    top: '5%',
                    left: '3%',
                    right: '8%',
                    bottom: '3%',
                    containLabel: true
                },
                legend: {
                    show: true,
                    data: t.chartData.data3[0]
                },
                xAxis: [{
                    type: 'category',
                    data: t.chartData.data1,
                    axisPointer: {
                        type: 'shadow'
                    }
                }],
                yAxis: [{
                        type: 'value',
                        axisLabel: {
                            formatter: '{value}'
                        }
                    },
                ],
                series: [
                    {
                        name: t.chartData.data3[0],
                        type: 'bar',
                        data: t.chartData.data2,
                        barWidth: 30
                    }
                    
                ]
            })
        }
    }
}
</script>

<style lang="scss" scoped>
</style>
